import socket

from src.Front.service.socket_abc import BaseSocket


class SocketClient(BaseSocket):

    def __init__(self):
        self.socket = None
        self.has_open = False

    def start(self):
        self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        self.socket.connect(('localhost', 33333))
        self.has_open = True
        print('[info] socket client start')

    def send_msg(self, msg):
        print('[info] ready to send msg')
        temp_msg = bytes(msg, encoding='utf-8')
        self.socket.sendall(temp_msg)
        print('[info] send msg success')


if __name__ == '__main__':
    c = SocketClient()
    c.start()
